function popup(id){
	$("#"+id).show();
}
function popuphide(id){
	$("#"+id).hide();
}
function msgTip(msg){
	$("#tip_msg_content").html(msg);
	popup('tip_msg');
}
function toGame(){  
	var actId = $("#actId").val();
	var openid = $("#openid").val();
	var subscribe = $("#subscribe").val();
	var jwid = $("#jwid").val();
	var appid = $("#appid").val();
	var url = "../../commongivebless/yn/toGame.do";
	url = url + "?actId=" + actId + "&openid="+ openid
	+ "&subscribe=" + subscribe+"&jwid=" + jwid+"&appid=" + appid;
	location.href=url;
}  

function validFocusBinding(btn){
	var actId = $("#actId").val();
	var openid = $("#openid").val();
	var subscribe = $("#subscribe").val();
	var jwid = $("#jwid").val();
	var appid = $("#appid").val();
	var nickname = $("#nickname").val();
//	if(subscribe==0){
//		popup("act_focus");
//		return;
//	}
	var url = "../../commongivebless/yn/validBinding.do";
	$.ajax({
		url:url,
		type:"post",
		data:{
			openid:openid,
			jwid:jwid
		},
		dataType:"json",
		success: function(data){
			if(data.success){
				if(btn=='1'){
					var url = "../../commongivebless/yn/toInformation.do";
					url = url + "?actId=" + actId + "&openid="+ openid
					+ "&subscribe=" + subscribe+"&jwid=" + jwid+"&appid=" + appid;
					location.href=url;
				}else if(btn=='2'){
					toMyRecord();
				}else if(btn=='3'){
					exchangeNow();
				}else if(btn=='4'){
					var url = "../../commongivebless/yn/toIndex.do";
					url = url + "?actId=" + actId + "&openid="+ openid
					+ "&subscribe=" + subscribe+"&jwid=" + jwid+"&appid=" + appid;
					location.href=url;
				}
			}else{
				if(data.obj=="isNotFocus"){
					popup('act_focus');
				}else if(data.obj=="isNotBind"){
					popup('isNotBind');
				}else{
					msgTip(data.msg);
				}
			}
		}
	});
}

function toBless(){  
	var actId = $("#actId").val();
	var openid = $("#openid").val();
	var subscribe = $("#subscribe").val();
	var jwid = $("#jwid").val();
	var appid = $("#appid").val();
	var nickname = $("#nickname").val();
	var url = "../../commongivebless/yn/toBless.do";
	url = url + "?actId=" + actId + "&openid="+ openid
	+ "&subscribe=" + subscribe+"&jwid=" + jwid+"&appid=" + appid;
	location.href=url;
}  
function toMyRecord(){  
	var actId = $("#actId").val();
	var openid = $("#openid").val();
	var fxOpenid = $("#fxOpenid").val();
	var subscribe = $("#subscribe").val();
	var jwid = $("#jwid").val();
	var appid = $("#appid").val();
	var registrationId = $("#registrationId").val();
	var url = "../../commongivebless/yn/toMyRecord.do";
	url = url + "?actId=" + actId + "&openid="+ openid+"&fxOpenid="+fxOpenid+"&registrationId="+registrationId
	+ "&subscribe=" + subscribe+"&jwid=" + jwid+"&appid=" + appid;
	location.href=url;
}
function doExchange() { 
	tiploadingTip("正在充值，请稍候。。。");
	$("#tixian").attr("disabled","true");
	var actId = $("#actId").val();
	var openid = $("#openid").val();
	var subscribe = $("#subscribe").val();
	var jwid = $("#jwid").val();
	var phone = $("#phone").val();
	if (phone == '') {
		alert("请输入手机号");
		return
	}else if (!isMobile(phone)){
		alert("手机号格式不正确，请重新输入！");
		return
	}
	var url = "../../commongivebless/yn/doExchange.do";
	$.ajax({
		url : url,
		type : 'post',
		dataType : 'json',
		async:true,
		data : {
			actId : actId,
			openid : openid,
			jwid : jwid,
			mobile:phone
		},
		success : function(data, status) {
			popuphide('tip_loading');
			if (data.success) {
//				if(data.obj){
					popup('success');
//				}else{
//					popup('tip_msg');
//				}
			} else {
				msgTip(data.msg);
			}
			$("#tixian").removeAttr("disabled");
		}
	});
} 

function tiploadingTip(msg){
	$("#tip_loading_content").html(msg);
	popup('tip_loading');
}

function exchangeNow(){  
	var actId = $("#actId").val();
	var openid = $("#openid").val();
	var subscribe = $("#subscribe").val();
	var jwid = $("#jwid").val();
	var url = "../../commongivebless/yn/getBindingPhone.do";
	$.ajax({
		url : url,
		type : 'post',
		dataType : 'json',
		data : {
			actId : actId,
			openid : openid,
			jwid : jwid
		},
		success : function(data, status) {
			if (data.success) {
				$("#phone").val(data.obj);
				popup('chongzhi');
			} else {
				msgTip(data.msg);
			}
		}
	});
} 

function shareNum() {  
	var actId = $("#actId").val();
	var url = "../../commongivebless/yn/shareNum.do";
	$.ajax({
		url : url,
		type : 'post',
		dataType : 'json',
		data : {
			actId : actId
		},
		success : function(data, status) {
			if (data.success) {

			}
		}
	});
	
}

//手机号数字正则验证
function isMobile(s) {
	var patrn = /^1((3\d)|(4[579])|(5[012356789])|(7[01235678])|(8\d))\d{8}$/;
	if (!patrn.exec(s))
		{return false;}
	return true;
}



